package com.tiny.myagent.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.Log;

public class BootCompleteReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("开机自启==", "我接收到广播啦");

        PackageManager packageManager = context.getPackageManager();
        intent = packageManager.getLaunchIntentForPackage("com.tiny.myagent");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

        /*Intent it = new Intent(context, MainActivity.class);
        it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(it);*/
        switch (intent.getAction()) {
            case Intent.ACTION_BOOT_COMPLETED:
                Log.i("开机自启==", "手机开机了");
                break;
            case Intent.ACTION_SHUTDOWN:
                Log.i("开机自启==", "手机关机了");
                break;
            case Intent.ACTION_SCREEN_ON:
                Log.i("开机自启==", "亮屏");
                break;
            case Intent.ACTION_SCREEN_OFF:
                Log.i("开机自启==", "息屏");
                break;
            case Intent.ACTION_USER_PRESENT:
                Log.i("开机自启==", "手机解锁");
                break;
        }
    }

}
